package cn.hello1023.springbootlabs.controller;

import cn.hello1023.springbootlabs.User;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloWorld {
    // http://localhost:28080/hello1?id=12
    @GetMapping("hello1")
    public String hello(@RequestParam(name = "id") String id ){
        System.out.println(id);
        return "Hello World1";
    }

    // http://localhost:28080/hello2/12
    @GetMapping("hello2/{id}")
    public String hello2(@PathVariable(name = "id") String id){
        //**********
        System.out.println(id);
        return "Hello World2";
    }

    /*
     http://localhost:28080/hello3  POST
     body -> json
         {
            "name":"zhang",
            "age":30
         }
     手动模拟发送json数据前，可以先检查一下json格式的正确性（https://www.sojson.com/）
     */
    @PostMapping("hello3")
    public String hello3(@RequestBody User user){
        //**********
        System.out.println(user.toString());
        return "Hello World3";
    }
}
